package com.saint.test_test;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMMessage;

public class MainActivity extends AppCompatActivity {
    private Activity act;
    private String userId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        act = this;

        getLoginDate("", "");
    }

    private void getLoginDate(String userName, String pwd) {
        userId = "55dacb7f1d83da60513ed7e172313f27";
        if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(pwd)) {
            Toast.makeText(this, "用户名密码不可为空！", Toast.LENGTH_SHORT).show();
            return;
        }

        EMClient.getInstance().login(userName, pwd, new EMCallBack() {
            @Override
            public void onSuccess() {
                if (EMClient.getInstance().getCurrentUser().equals(userId)){
                    Log.e("环信账号信息结果", " 不能和自己聊天 userId: " + userId );
                }else {
                    userId = "3e16227f3a31e5f7db2f35a3d8fcfbc1";
                }
                Intent intent = new Intent(act, ChatActivity.class);
                intent.putExtra("userId", userId);
                intent.putExtra("chatType", EMMessage.ChatType.Chat);
                startActivity(intent);
                Log.e("环信账号信息结果", "登陆成功" );
            }

            @Override
            public void onError(int i, String s) {
                Log.e("环信登陆失败", " code: " +  i + "  msg: " + s);
            }

            @Override
            public void onProgress(int i, String s) {

            }
        });
    }
}
